syntax = "proto3";

package ozonmp.act_device_api.v1;

import "validate/validate.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";

option go_package = "gitlab.ozon.dev/qa/classroom-4/act-device-api/pkg/act-device-api;act_device_api";

service ActNotificationApiService{

  rpc SendNotificationV1(SendNotificationV1Request) returns (SendNotificationV1Response){
    option (google.api.http) = {
      post: "/api/v1/notification"
      body: "*"
    };
  }


  rpc GetNotification(GetNotificationV1Request) returns (GetNotificationV1Response){
    option (google.api.http) = {
      get: "/api/v1/notification"
    };
  }


  rpc AckNotification(AckNotificationV1Request) returns (AckNotificationV1Response){
    option (google.api.http) = {
      put: "/api/v1/notification/ack/{notificationId}"
    };
  }



  rpc SubscribeNotification(SubscribeNotificationRequest) returns (stream UserNotification){
    option (google.api.http) = {
      get: "/api/v1/notification/subscribe/{deviceId}"
    };
  }


}
// ActDeviceApiService - Service for working with templates
service ActDeviceApiService {
  // CreateDeviceV1 - Create a device
  rpc CreateDeviceV1(CreateDeviceV1Request) returns (CreateDeviceV1Response) {
    option (google.api.http) = {
      post: "/api/v1/devices"
      body: "*"
    };
  }
  // DescribeDeviceV1 - Describe a device
  rpc DescribeDeviceV1(DescribeDeviceV1Request) returns (DescribeDeviceV1Response) {
    option (google.api.http) = {
      get: "/api/v1/devices/{device_id}"
    };
  }
  // ListDevicesV1 - List of devices
  rpc ListDevicesV1(ListDevicesV1Request) returns (ListDevicesV1Response) {
    option (google.api.http) = {
      get: "/api/v1/devices"
    };
  }
  // UpdateDeviceV1 - Update a device
  rpc UpdateDeviceV1(UpdateDeviceV1Request) returns (UpdateDeviceV1Response) {
    option (google.api.http) = {
      put: "/api/v1/devices/{device_id}"
      body: "*"
    };
  }
  // RemoveDeviceV1 - Remove a device
  rpc RemoveDeviceV1(RemoveDeviceV1Request) returns (RemoveDeviceV1Response) {
    option (google.api.http) = {
      delete: "/api/v1/devices/{device_id}"
    };
  }
}

message AckNotificationV1Request{
  uint64 notificationId = 1;
}

message AckNotificationV1Response{
  bool success = 1;
}

message SubscribeNotificationRequest{
  uint64 deviceId = 1;
}

message GetNotificationV1Request{
  uint64 deviceId = 1;
}


message GetNotificationV1Response{
  repeated UserNotification notification = 1;
}

message SendNotificationV1Request{
  Notification notification = 1;
}

message UserNotification{
  uint64  notificationId = 1;
  string message = 2;
}
message Notification{
  uint64  notificationId = 1;
  uint64 deviceId = 2;
  string username = 3;
  string message = 4;
  Language lang = 5;
  Status notificationStatus = 6;
}


message SendNotificationV1Response{
  uint64 notificationId = 1;
}


enum Language {
  LANG_ENGLISH = 0;
  LANG_RUSSIAN = 1;
  LANG_ESPANOL = 2;
  LANG_ITALIAN = 3;
}


enum Status {
  STATUS_CREATED = 0;
  STATUS_IN_PROGRESS = 1;
  STATUS_DELIVERED = 2;
}

message Device {
  uint64 id = 1;
  string platform = 2;
  uint64 user_id = 3;
  google.protobuf.Timestamp entered_at = 4;
}

message CreateDeviceV1Request {
  string platform = 1 [(validate.rules).string.min_len = 1];
  uint64 user_id = 2 [(validate.rules).uint64.gt = 0];
}

message CreateDeviceV1Response {
  uint64 device_id = 1;
}

message DescribeDeviceV1Request {
  uint64 device_id = 1 [(validate.rules).uint64.gt = 0];
}

message DescribeDeviceV1Response {
  Device value = 1;
}

message ListDevicesV1Request {
  uint64 page = 1;
  uint64 per_page = 2;
}

message ListDevicesV1Response {
  repeated Device items = 1;
}

message UpdateDeviceV1Request {
  uint64 device_id = 1 [(validate.rules).uint64.gt = 0];
  string platform = 2 [(validate.rules).string.min_len = 1];
  uint64 user_id = 3 [(validate.rules).uint64.gt = 0];
}

message UpdateDeviceV1Response {
  bool success = 1;
}

message RemoveDeviceV1Request {
  uint64 device_id = 1 [(validate.rules).uint64.gt = 0];
}

message RemoveDeviceV1Response {
  bool found = 1;
}

message DeviceEvent {
  uint64 id = 1 [(validate.rules).uint64.gt = 0];
  uint64 device_id = 2 [(validate.rules).uint64.gt = 0];
  uint64 type = 3 [(validate.rules).uint64.gt = 0];
  uint64 status = 4 [(validate.rules).uint64.gt = 0];
  Device payload = 5;
}
